﻿using Exam.infranstuctrue.Dto.Request.Exam;
using Exam.infranstuctrue.Dto.Request.Question;
using Exam.Service.Interface;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace Exam.Controllers
{
    [ApiController]
    public class QuestionController : BaseController
    {
        private readonly IQuestionServer _question;

        public QuestionController(IQuestionServer question)
        {
            _question = question;
        }
        /// <summary>
        /// 获取试题数据
        /// </summary>
        /// <param name="limit"></param>
        /// <param name="page"></param>
        /// <param name="key"></param>
        /// <param name="IsBan"></param>
        /// <param name="IsPublish"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> GetQuestion(int page = 1, int limit = 10, string? key = "", int IsBan = -1, int IsPublish = -1)
        {
            key = key ?? "";
            var result = await _question.GetQuestion(page, limit, key, IsBan, IsPublish);
            return Ok(result);
        }
        /// <summary>
        /// 添加试题
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> AddQuestion(List<QuestionDto> dto)
        {
            var result = await _question.AddQuestion(dto);
            return Ok(result);
        }
        ///<summary>
        /// 获取单个试题
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> UpdateEchoQuestion(QuestionDto dto)
        {
            var result = await _question.UpdateEchoQuestion(dto);
            return Ok(result);
        }
        /// <summary>
        /// 删除试题
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> DeleteQuestion(List<QuestionDto> dto)
        {
            var result = await _question.DeleteQuestion(dto);
            return Ok(result);
        }
        /// <summary>
        /// 是否发布
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> IsPublish(List<QuestionDto> dto)
        {
            var result = await _question.IsPublish(dto);
            return Ok(result);
        }
        /// <summary>
        /// 是否禁用
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> IsBna(List<QuestionDto> dto)
        {
            var result = await _question.IsBan(dto);
            return Ok(result);
        }

    }
}
